#include <iostream>
#include <list>

using std::cout;
using std::endl;
using std::list;

template <typename Container>
void display(const Container &con)
{
    for(auto &elem : con)
    {
        cout << elem << "  ";
    }
    cout << endl;
}

void test()
{
    list<int> number = {1, 4, 8, 9, 3, 5};
    list<int> other = {11, 66, 88, 22, 77};
    display(number);
    display(other);

#if 0
    cout << endl << endl;
    auto pos = number.begin();
    ++pos;
    cout << "*pos = " << *pos << endl;
    number.splice(pos, other);
    display(number);
    display(other);
#endif
    cout << endl << endl;
    auto pos = number.begin();
    ++pos;
    cout << "*pos = " << *pos << endl;
    auto it = other.end();
    --it;
    --it;
    cout << "*it = " << *it << endl;
    number.splice(pos, other, it);
    display(number);
    display(other);

    cout << endl << endl;
    cout << "*pos = " << *pos << endl;
    it = other.begin();
    ++it;
    cout << "*it = " << *it << endl;
    auto it2 = other.end();
    --it2;
    cout << "*it2 = " << *it2 << endl;
    number.splice(pos, other, it, it2);
    display(number);
    display(other);

    cout << endl << "在同一个链表中的操作" << endl;
    pos = number.begin();
    ++pos;
    ++pos;
    cout << "*pos = " << *pos << endl;
    auto cit = number.end();
    --cit;
    cout << "*cit = " << *cit << endl;
    number.splice(pos, number, cit);
    display(number);
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

